//
//  PacketBodyBuffer.m
//  HelloWorld
//
//  Created by Martin Le C. on 5/14/09.
//  Copyright 2009 __MyCompanyName__. All rights reserved.
//

#import "PacketBodyBuffer.h"
UInt8 const SEPARATOR[2] = {0xc0, 0x80};

@implementation PacketBodyBuffer
@synthesize baos;
-(id) init {
	self.baos = [NSMutableData data];
	return self;
}
// -----------------------------------------------------------------
// Add a string to the buffer, and terminate with separator.
// Note: this method is NOT thread safe.
// -----------------------------------------------------------------
-(void)addString:(NSString*)s {	
	[self.baos appendData: [s  dataUsingEncoding:NSUTF8StringEncoding]];
    [self.baos appendBytes:SEPARATOR length:2];
}
// -----------------------------------------------------------------
// Add key/value pair to buffer.
// Note: this method is NOT thread safe.
// -----------------------------------------------------------------
-(void)addElement:(NSString*)key value:(NSString*)value {	
	[self addString:key];  
	[self addString:value];
}
// -----------------------------------------------------------------
// Reset (clear) buffer
// -----------------------------------------------------------------
-(void)reset {
	[self.baos release];
}
@end